Component({
  data: {
    morphineInjection: "", //吗啡针剂
    morphineTablets: "", //吗啡片剂
    morphineSulfate: "", //硫酸吗啡缓释片
    OxycodoneHydrochloride: "", //盐酸羟考酮缓释片
    fentanyl: "", //fentanyl
    breakthroughPain: "",
    sumT:""
  },
  methods: {
    // 吗啡针剂
    morphineInjectionFn(e) {
      this.setData({
        morphineInjection: e.detail.value
      })

      this.outbreakFn()
    },

    //吗啡片剂
    morphineTabletsFn(e) {
      this.setData({
        morphineTablets: e.detail.value
      })

      this.outbreakFn()
    },

    //硫酸吗啡缓释片
    morphineSulfateFn(e) {
      this.setData({
        morphineSulfate: e.detail.value
      })

      this.outbreakFn()

    },
    //盐酸羟考酮缓释片
    OxycodoneHydrochlorideFn(e) {
      this.setData({
        OxycodoneHydrochloride: e.detail.value
      })

      this.outbreakFn()

    },

    // 芬太尼贴剂
    fentanylFn(e) {
      this.setData({
        fentanyl: e.detail.value
      })

      this.outbreakFn()
    },

    calculate(value) {
      return Math.round(value * 100) / 100
    },

    outbreakFn() {
      let sum = Number(this.data.morphineInjection * 3) + Number(this.data.morphineTablets) + Number(this.data.morphineSulfate) + Number(this.data.OxycodoneHydrochloride * 1.5) + this.calculate(this.data.fentanyl/4.2 * 60)
      
      this.setData({
        breakthroughPain: `${this.calculate(sum * 0.1)} ~ ${this.calculate(sum * 0.2)}`
      })


      this.setData({
        sumT: `${this.calculate(sum * 0.1 / 3)} ~ ${this.calculate(sum * 0.2 / 3)}`
      })

    }


  }
})